﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using System.Collections.Generic;
using ClassLibrary.Entity;

public partial class Yumcha_UcControl_ucMenu1 : System.Web.UI.UserControl
{
    TblMenuDAO menuDAO = new TblMenuDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadMenuYumCha();
           
        }
        UpdateShoppingCartSession();
    }
    private void LoadMenuYumCha()
    {
        try
        {
            lvYumCha.DataSource = menuDAO.GetMenu_Wedding(1);
            lvYumCha.DataBind();
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect("~/Wedding/Error.aspx", true);
        }
    }

    protected void btnImage_Click(object sender, ImageClickEventArgs e)
    {
        bool flag = false;
        try
        {
            string IdItem = ((ImageButton)sender).CommandArgument;
            ImageButton imagebutton = (ImageButton)sender;

            BasePage.SetShoppingCartSesstion(IdItem + "|0");

            List<TblBookingDetail> arrItems = new List<TblBookingDetail>();
            if (Session[Global.SESSION_CART] != null)
                arrItems = (List<TblBookingDetail>)Session[Global.SESSION_CART];

            int iNoOfItems = 0;
            double dTotalAmount = 0;

            foreach (TblBookingDetail order in arrItems)
            {
                iNoOfItems += order.Quantity;
                dTotalAmount += Convert.ToDouble(order.Quantity) * Convert.ToDouble(order.Price);
            }

            flag = true;
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE, true);
        }
        if (flag)
            Response.Redirect("~/Yumcha/AlaCarteMenu.aspx");
    }

    public void UpdateShoppingCartSession()
    {
        if (HttpContext.Current.Session[Global.SESSION_CART] != null)
        {
            List<TblBookingDetail> cartItems = (List<TblBookingDetail>)HttpContext.Current.Session[Global.SESSION_CART];

            int iQuantity = 0;
            double dAmount = 0;
            foreach (TblBookingDetail order in cartItems)
            {
                iQuantity += order.Quantity;
                //dAmount +=  order.TotalAmount;
                dAmount += Convert.ToDouble(order.Quantity) * Convert.ToDouble(order.Price);
            }
            lbsoluong.Text = iQuantity.ToString();
            lblAmout.Text = dAmount.ToString("c");
        }
    }
    protected void lvYumCha_ItemDataBound(object sender, ListViewItemEventArgs e)
    { if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            // Display the e-mail address in italics.
            Label lb_Price = (Label)e.Item.FindControl("lbPrice");

            DataTable dt = null;
            dt = menuDAO.GetMenu_Wedding(1);

            lb_Price.Text = "$";

            
        }
       
    }
}
